reading-notes

Trees 🌳🌲🎄


  1. Node - A node is the individual item/data that makes up the data structure
  2. Root - The root is the first/top Node in the tree
  3. Left Child - The node that is positioned to the left of a root or node
  4. Right Child - The node that is positioned to the right of a root or node
  5. Edge - The edge in a tree is the link between a parent and child node
  6. Leaf - A leaf is a node that does not contain any children
  7. Height - The height of a tree is determined by the number of edges from the root to the bottommost node.

Depth First

Binary Trees

In all of our examples, we’ve been using a Binary Tree. Trees can have any number of children per node, but Binary Trees restrict the number of children to two (hence our left and right children).

There is no specific sorting order for a binary tree. Nodes can be added into a binary tree wherever space allows. Here is what a binary tree looks like:

Binary Search Trees

A Binary Search Tree (BST) is a type of tree that does have some structure attached to it. In a BST, nodes are organized in a manner where all values that are smaller than the root are placed to the left, and all values that are larger than the root are placed to the right.

Here is how we would change our Binary Tree example into a Binary Search Tree:

Big O in Trees